#include "stdafx.h"
#include "Log.h"


static const char* WARNING_PREFIX = "[Warning] ";
static const char* ERROR_PREFIX = "[Error] ";
static const char* CRITICAL_ERROR_PREFIX = "[CriticalError] ";

CLog::CLog(IConsole* pConsole)
: m_pConsole(pConsole)
{

}

void CLog::log(const char* message, ...)
{
	va_list args;
	va_start(args, message);
	string text = string_utils::format(message, args);
	va_end(args);

	string console_text = text;
	m_pConsole->AddLine(console_text.c_str());
}

void CLog::warning(const char* message, ...)
{
	va_list args;
	va_start(args, message);
	string text = string(WARNING_PREFIX) + string_utils::format(message, args);
	va_end(args);

	string console_text = string("$7") + text;
	m_pConsole->AddLine(console_text.c_str());
}

void CLog::error(const char* message, ...)
{
	va_list args;
	va_start(args, message);
	string text = string(ERROR_PREFIX) + string_utils::format(message, args);
	va_end(args);

	string console_text = string("$3") + text;
	m_pConsole->AddLine(console_text.c_str());
}

void CLog::critical_error(const char* message, ...)
{
	va_list args;
	va_start(args, message);
	string text = string(CRITICAL_ERROR_PREFIX) + string_utils::format(message, args);
	va_end(args);

	string console_text = string("$3") + text;
	m_pConsole->AddLine(console_text.c_str());
}